package com.shop2cn.iapi.accounting.testcase;

import java.math.BigDecimal;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.accounting.parameter.GetAccountBalanceBean;
import com.shop2cn.iapi.accounting.service.GetAccountBalanceCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.shenqi.AccountCallServiceV2;
import com.ymttest.database.model.Account;
import com.ymttest.database.sqlwapper.AccountWapper;
/**
*根据用户编号和账户类型获取账户余额接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetAccountBalance{
	private static GetAccountBalanceBean getaccountbalanceBean;
	private static GetAccountBalanceCall getaccountbalanceCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据用户编号和账户类型获取账户余额接口");
	}

	@Before
	public void caseUp() {
		getaccountbalanceBean=new GetAccountBalanceBean();
		getaccountbalanceCall=new GetAccountBalanceCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getaccountbalanceCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetAccountBalance_001() {
		Logger.start(true,"根据用户编号和账户类型获取账户余额成功");
		try {	
			Logger.comment("前置条件");
			String accountid1 = AccountCallServiceV2.getAccountId(21000000);
			int userId=21000000;
			AccountCallServiceV2.resetAccount(accountid1, new BigDecimal(10), new BigDecimal(20));
			Logger.comment("前置条件设置结束");
			int accountType=1;
			getaccountbalanceBean.setUserId(userId);
			getaccountbalanceBean.setAccountType(accountType);
			getaccountbalanceBean.setAppId("AutoTest");
			getaccountbalanceCall.setData(getaccountbalanceBean);
			getaccountbalanceCall.callService();			
			List<Account> aids= new AccountWapper().selectAccountInfoByUserId(userId,accountType);				
			Logger.verifyEquals(0, getaccountbalanceCall.getStatus(), "验证StatusCode");
			Logger.verifyEquals((String)aids.get(0).getAccountId(), getaccountbalanceCall.getAccountId(),"验证接口返回AccountInfoId跟数据库是否一致");
			Logger.verifyEquals(0,((BigDecimal)aids.get(0).getAvailAmount()).compareTo(new BigDecimal(getaccountbalanceCall.getAvailAmount())),"验证接口返回AvailAmount:"+getaccountbalanceCall.getAvailAmount()+"跟数据库是否一致");
			Logger.verifyEquals(0,((BigDecimal)aids.get(0).getFreezeAmount()).compareTo(new BigDecimal(getaccountbalanceCall.getFreezeAmount())),"验证接口返回FreezeAmount:"+getaccountbalanceCall.getFreezeAmount()+"跟数据库是否一致");			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetAccountBalance_002() {
		Logger.start(false,"用户编号不存在,获取账户余额返回空");
		try {
			int userId=0;
			int accountType=1;
			getaccountbalanceBean.setUserId(userId);
			getaccountbalanceBean.setAccountType(accountType);
			getaccountbalanceBean.setAppId("AutoTest");
			getaccountbalanceCall.setData(getaccountbalanceBean);
			getaccountbalanceCall.callService();			
			Logger.verifyEquals(0, getaccountbalanceCall.getStatus(), "验证StatusCode");
			Logger.verifyIsNull(getaccountbalanceCall.getData(), "验证返回的data为null");		
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetAccountBalance_003() {
		Logger.start(false,"账户类型不存在,获取账户余额失败");
		try {
			int userId=99210932;
			int accountType=4;
			getaccountbalanceBean.setUserId(userId);
			getaccountbalanceBean.setAccountType(accountType);
			getaccountbalanceBean.setAppId("AutoTest");
			getaccountbalanceCall.setData(getaccountbalanceBean);
			getaccountbalanceCall.callService();
			Logger.verifyEquals(0, getaccountbalanceCall.getStatus(), "验证StatusCode");
			Logger.verifyIsNull(getaccountbalanceCall.getData(), "验证返回的data为null");	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetAccountBalance_004() {
		Logger.start(false,"用户编号为空,获取账户余额,返回空");
		try {
			int accountType=1;
			//getaccountbalanceBean.setUserId(userId);
			getaccountbalanceBean.setAccountType(accountType);
			getaccountbalanceBean.setAppId("AutoTest");
			getaccountbalanceCall.setData(getaccountbalanceBean);
			getaccountbalanceCall.callService();			
			Logger.verifyEquals(0, getaccountbalanceCall.getStatus(), "验证StatusCode");
			Logger.verifyIsNull(getaccountbalanceCall.getData(), "验证返回的data为null");	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetAccountBalance_005() {
		Logger.start(true,"账户类型为空,获取账户余额,获取成功");
		try {
			int userId=21000002;
			getaccountbalanceBean.setUserId(userId);
			//getaccountbalanceBean.setAccountType(accountType);
			getaccountbalanceBean.setAppId("AutoTest");
			getaccountbalanceCall.setData(getaccountbalanceBean);
			getaccountbalanceCall.callService();			
			List<Account> aids= new AccountWapper().selectAccountInfoByUserId(userId,1);				
			Logger.verifyEquals(0, getaccountbalanceCall.getStatus(), "验证StatusCode");
			Logger.verifyEquals((String)aids.get(0).getAccountId(), getaccountbalanceCall.getAccountId(),"验证接口返回AccountInfoId跟数据库是否一致");
			Logger.verifyEquals(0,((BigDecimal)aids.get(0).getAvailAmount()).compareTo(new BigDecimal(getaccountbalanceCall.getAvailAmount())),"验证接口返回AvailAmount:"+getaccountbalanceCall.getAvailAmount()+"跟数据库是否一致");
			Logger.verifyEquals(0,((BigDecimal)aids.get(0).getFreezeAmount()).compareTo(new BigDecimal(getaccountbalanceCall.getFreezeAmount())),"验证接口返回FreezeAmount:"+getaccountbalanceCall.getFreezeAmount()+"跟数据库是否一致");			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetAccountBalance_006() {
		Logger.start(false,"应用编号为空,获取账户余额失败");
		try {
			int userId=99210932;
			int accountType=1;
			getaccountbalanceBean.setUserId(userId);
			getaccountbalanceBean.setAccountType(accountType);
			//getaccountbalanceBean.setAppId("AutoTest");
			getaccountbalanceCall.setData(getaccountbalanceBean);
			getaccountbalanceCall.callService();			
			Logger.verifyEquals(2, getaccountbalanceCall.getStatus(), "验证StatusCode");
			Logger.verifyIsNull(getaccountbalanceCall.getData(), "验证返回的data为null");	
			Logger.verifyEquals("AppId不能为空！", getaccountbalanceCall.getMsg(), "验证错误提示信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}